<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include('menu.php'); ?>
</head>
<body>
<?php
include("../connect/connect.php");

//แก้ไข
if($_GET["action"]=="update") {

	if($_POST['code'] != "" AND $_POST['price'] != "" AND $_POST['category_id'] != "" AND $_POST['rop'] != "" AND $_POST['status'] != "")
		{
			$Query = "UPDATE product SET prod_barcode = '".$_POST["code"]."',prod_price = '".$_POST["price"]."',prodtype_id = '".$_POST["category_id"]."',prod_rop = '".$_POST["rop"]."',prod_status = '".$_POST["status"]."' WHERE prod_id = '".$_POST["product_id"]."' ";
			$objQuery = mysql_query($Query);
			
			echo "<script type=\"text/javascript\"> window.location=\"product_manage.php\"</script>";
			exit();
		}
}

$Query = "SELECT * FROM product,producttype WHERE product.prodtype_id = producttype.prodtype_id and prod_id = '".$_GET["id"]."'";
$objQuery = mysql_query($Query) or die ("Error Query [".$Query."]");
$row = mysql_fetch_array($objQuery);
?>
<form action="?action=update" name="formedit" method="post" id="formedit">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>แก้ไขข้อมูลสินค้า</h1>
    <div class="buttons"><a onclick="formedit.submit();" class="button"><span>บันทึก</span></a><a onclick="location = 'product_manage.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
    <table class="form">
      <tr>
        <td>รหัสสินค้า : </td>
        <td><input name="code" type="text" readonly="readonly" id="code" value="<?php echo $row["prod_barcode"];?>" />
        *ไม่สามารถแก้ไขได้
		  <input name="product_id" type="hidden" id="product_id" value="<?php echo $row["prod_id"];?>" /></td>
      </tr>
      <tr>
        <td>ชื่อสินค้า : </td>
        <td><input name="name" type="text" id="name" readonly="readonly" value="<?php echo $row["prod_name"];?>" /> *หากต้องการแก้ไขให้ปิดสถานะเป็นไม่แสดง แล้วเพิ่มสินค้าใหม่แทน</td>
      </tr>
      <tr>
        <td>หมวดสินค้า : </td>
        <td><select name="category_id" id="category_id">
		<?php
			$Querycate = "SELECT * FROM producttype ORDER BY prodtype_id";
			$objQuerycate = mysql_query($Querycate);
			$strNum=0;
			while($row1 = mysql_fetch_array($objQuerycate))
			{
			$strNum++;
		?>
          <option <?php if($row["prodtype_id"]==$row1["prodtype_id"]) {echo "selected";} ?> value="<?php echo $row1["prodtype_id"];?>"><?php echo $strNum." - ".$row1["prodtype_name"];?></option>
                <?php
			}
			?>
        </select></td>
      </tr>
      <tr>
        <td>ราคาขาย : </td>
        <td><input name="price" type="text" id="price" value="<?php echo $row["prod_price"];?>" /></td>
      </tr>
      <tr>
        <td>จุดสั่งซื้อ : </td>
        <td><input name="rop" type="text" id="rop" value="<?php echo $row["prod_rop"];?>" /></td>
      </tr>
      <tr>
        <td>สถานะ : </td>
        <td><label><input type="radio" name="status" value="0" <?php if($row['prod_status']=='0'){ echo "checked=\"checked\"";} ?> />แสดง</label> <label><input type="radio" name="status" value="1" <?php if($row['prod_status']=='1'){ echo "checked=\"checked\"";} ?> />ไม่แสดง</label> </td>
      </tr>
    </table>
  </div>
</div>
</form>
</body>
<?php mysql_close(); ?>
</html>
